<?php

declare(strict_types=1);

namespace Modules\Production\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $docno
 * @property $doc_type
 * @property $status
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class MaterialReturnOrder extends Model
{

    protected $table = 'material_return_order';

    protected $fillable = [ 'id', 'docno', 'doc_type', 'status', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','docno','doc_type','status','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','docno','doc_type','status','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'docno'     => '=',
        'doc_type'  => '=',
        'status'    => '=',
    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    /**
     * 返回订单明细
     * @return HasMany
     */
    public function detail():HasMany
    {
        return $this->hasMany(MaterialReturnDetail::class,'order_id');
    }
}
